//
//  HESettingSwitchCell.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/11/11.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HESettingSwitchCell.h"

@interface HESettingSwitchCell ()

@property(nonatomic, strong) UIImageView *arrowView;
@property(nonatomic, strong) UISwitch *openBtn;
@end

@implementation HESettingSwitchCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        [self initUI];
    }
    return self;
}

- (void)initUI {
    self.textLabel.font = DYFont(16);

//    _arrowView = [UIImageView new];
//    _arrowView.contentMode = UIViewContentModeScaleAspectFill;
//    _arrowView.image = IMAGE_NAMED(@"go_gray");
//    [self.contentView addSubview:_arrowView];
//
//    [_arrowView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.centerY.equalTo(self.contentView);
//        make.right.equalTo(self.contentView).mas_offset(-15);
//        make.width.mas_offset(8);
//        make.height.mas_offset(12);
//    }];
    
    _openBtn = [UISwitch new];
   [_openBtn addTarget:self action:@selector(switchChange:) forControlEvents:UIControlEventValueChanged];   // 开关事件切换通知
   [self.contentView addSubview:_openBtn];
    
    [_openBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.contentView);
        make.right.equalTo(self.contentView).mas_offset(-15);
    }];
}

- (void)switchChange:(UISwitch *)sender{
    if ([_delegate respondsToSelector:@selector(switchChange:)]) {
        [_delegate switchChange:self];
    }
}

- (void)refreshContent:(GDFiterCellModel *)fiterModel formModel:(GDFormModel *)formModel indexPath:(NSIndexPath *)indexPath {
    self.delegate = formModel.proxyVC;
    self.textLabel.text = fiterModel.leftTitle;
    
    NSNumber *bl = [formModel valueForKey:fiterModel.tableKey];
    _openBtn.on = bl.boolValue;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
